package com.ninedash.app;

import android.app.Activity;
import android.app.ListFragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by Lenovo on 14年4月26日.
 */
public class RestaurantListFragment extends ListFragment {

    OnBlockSelectedListener mCallback;
    ArrayList<HashMap<String,String>> mListData;

    public RestaurantListFragment() {

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        String[] values = new String[] { "McDonlad's", "Cafe de Coral", "Golden Bowl" };
        HashMap<String,String> myMap = new HashMap<String, String>();
        mListData = new ArrayList<HashMap<String, String>>();
        for(int i = 0; i < values.length; i++) {
            myMap.put("rest_name",values[0]);
            myMap.put("num_of_tables","100");
            mListData.add(myMap);
        }


        RestaurantListAdapter adapter = new RestaurantListAdapter(mListData);

        setListAdapter(adapter);


        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ListView lv = getListView();
        lv.setDivider(null);

    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        // do something with the data
        mCallback.onBlockSelected(mListData.get(position));

    }

    public interface OnBlockSelectedListener {
        public void onBlockSelected(HashMap<String,String> reportData);
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);

        // This makes sure that the container activity has implemented
        // the callback interface. If not, it throws an exception
        try {
            mCallback = (OnBlockSelectedListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement OnBlockListener");
        }
    }
}
